namespace Mytodotodaylist.Core.Schedule
{
    using Events;
    using Notifications;

    public class EvaluationTask : ITask
    {
        private readonly IEventRepository EventRepository;
        private readonly INotificationService NotificationService;
        private EventOcurrenceEvaluationFilter evaluationFilter;

        public EvaluationTask(
            IEventRepository  eventRepository, 
            INotificationService notificationService)
        {
            EventRepository = eventRepository;
            EventRepository = eventRepository;
            NotificationService = notificationService;
            
            evaluationFilter = new EventOcurrenceEvaluationFilter();
        }

        public void Execute()
        {
            var events = EventRepository.GetAll();

            if(events.Count > 0)
            {
                var occurenceEventList = evaluationFilter.Applay(events);

                if (occurenceEventList.Count > 0)
                    NotificationService.NotifyEvents(occurenceEventList);
            }
        }
    }
}